﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using TaxiService.Model;

namespace TaxiService.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "NguoiDungService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select NguoiDungService.svc or NguoiDungService.svc.cs at the Solution Explorer and start debugging.
    public class NguoiDungService : INguoiDungService
    {

        public bool AddNguoiDung(NguoiDung user)
        {
            try
            {
                using (var context = new TaxiEntities())
                {
                    var currentuser = context.NguoiDungs.SingleOrDefault(n => n.MaMay.Equals(user.MaMay));
                    if (currentuser == null)
                    {
                        context.NguoiDungs.Add(user);
                        context.SaveChanges();
                        return true;
                    }
                    else
                        return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }

        }
    }
}
